﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace lazy
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("----------------欢迎进入游戏世界----------------");
            Console.WriteLine("*******************************");
            Console.WriteLine("********心里博弈之猜拳*********");
            Console.WriteLine("*******************************");
            Console.WriteLine("游戏规则：1、剪刀 2、石头 3、布");
            NPC d = new NPC();
            Player w = new Player();
            Mora m = new Mora();
            while (true)
            {
                bool Q = true;
                d.NPCname();
                w.Playername();
                Console.WriteLine("{0}  vs  {1}",w.Name,d.Name);
                Console.WriteLine("要开始对局吗？(y/n)");
                string yn = Console.ReadLine();
                switch (yn)
                {
                    case "y":
                        m.morap();
                        m.moran();
                        Console.WriteLine("{0}: 出招:{1}",w.Name,m.PlayerMora);
                        Console.WriteLine("{0}: 出招:{1}",d.Name,m.NPCMora);
                        m.Theending();
                        while (Q)
                        {
                            int record = 0;
                            record++;
                            Console.WriteLine("是否开始下一轮？(y/n)");
                            string q = Console.ReadLine();
                            switch (q)
                            {
                                case "y":
                                    m.morap();
                                    m.moran();
                                    Console.WriteLine("{0}: 出招:{1}", w.Name, m.PlayerMora);
                                    Console.WriteLine("{0}: 出招:{1}", d.Name, m.NPCMora);
                                    m.Theending();
                                    break;
                                case "n":
                                    Console.WriteLine("=====================================");
                                    Console.WriteLine("{0}  vs  {1}",w.Name,d.Name);
                                    Console.WriteLine("对战次数：" + record);
                                    Console.WriteLine("姓名\t得分 ");
                                    Console.WriteLine("{0}\t{1}",w.Name,m.Win1);
                                    Console.WriteLine("{0}\t{1}",d.Name,m.Defeat1);
                                    if (m.Win1>m.Defeat1)
                                    {
                                        Console.WriteLine("结果：{0}赢,{1}不行不行",w.Name,d.Name);
                                    }
                                    else if (m.Win1<m.Defeat1)
                                    {
                                        Console.WriteLine("结果：{0}赢,{1}不行不行",d.Name,w.Name);
                                    }
                                    else if (m.Win1==m.Defeat1)
                                    {
                                        Console.WriteLine("结果：平局");
                                    }
                                    Q = false;
                                    break;
                            }
                        }
                        break;
                    case "n":
                        Console.WriteLine("不玩你进来干嘛？？？");
                        break;
                }
                Console.WriteLine("是否开始下一局？（y/n）");
                string u = Console.ReadLine();
                if (u=="y")
                {
                    continue;
                }
                else if (u=="n")
                {
                    Console.WriteLine("游戏结束!");
                    break;
                }
            }
        }
    }
    class NPC
    {
        public string name;

        public string Name { get => name; set => name = value; }
        public void NPCname()
        {
            Console.WriteLine("请选择对方角色：1、刘备2、孙权 3、曹操");
            int enemy = int.Parse(Console.ReadLine());
            switch (enemy)
            {
                case 1:
                    Name = "刘备";
                    break;
                case 2:
                    Name = "孙权";
                    break;
                case 3:
                    Name = "曹操";
                    break;
                  
            }
            Console.WriteLine("我是{0}不斩无名之辈。阁下,告诉我你的名字：", Name);
        }
    }
    class Player
    {
        public string name;

        public string Name { get => name; set => name = value; }
        public void Playername() 
        {
            Name =Console.ReadLine();
        }
    }
    class Mora
    {
        private string playerMora;
        private string nPCMora;
        private int Win = 0;
        private int Defeat = 0;
        private int a;
        private int b;

        public string PlayerMora { get => playerMora; set => playerMora = value; }
        public string NPCMora { get => nPCMora; set => nPCMora = value; }
        public int A { get => a; set => a = value; }
        public int B { get => b; set => b = value; }
        public int Win1 { get => Win; set => Win = value; }
        public int Defeat1 { get => Defeat; set => Defeat = value; }

        public void morap()
        {
            Console.WriteLine("请选择你的招式：1、剪刀  2、石头  3、布  <输入数字即可>");
            A = int.Parse(Console.ReadLine());
            switch (A)
            {
                case 1:
                    PlayerMora = "剪刀";
                    break;
                case 2:
                    PlayerMora = "石头";
                    break;
                case 3:
                    PlayerMora = "布";
                    break;
            }
        }
        public void moran() 
        {
            Random random = new Random();
            B = random.Next(1, 4);
            switch (B)
            {
                case 1:
                    NPCMora = "剪刀";
                    break;
                case 2:
                    NPCMora = "石头";
                    break;
                case 3:
                    NPCMora = "布";
                    break;
            }
        }
        public void Theending() 
        {
            if (A==B)
            {
                Console.WriteLine("和局？你真不行。");
            }
            else if (A==1 && B==3 || A==2 && B==1 || A==3 && B==2)
            {
                Console.WriteLine("不错，你赢了。");
                Win1++;
            }
            else if(B == 1 && A == 3 || B  == 2 && A == 1 || B == 3 && A == 2)
            {
                Console.WriteLine("输的真惨!!!");
                Defeat1++;
            }
        }
    }
}
